package com.yxj.lib_exo;

import java.util.Locale;

/**
 * 播放时视频  时间相关的
 */
public final class ExoVideoTimeUtil {


    // 格式化时间为 HH:MM:SS 格式
    public static String formatTime(long timeMs) {

        if (timeMs <= 0) return "00:00";

        long totalSeconds = (timeMs + 500) / 1000;
        //小时
        long hours = totalSeconds / (60 * 60);
        //分
        long minutes = (totalSeconds % (60 * 60)) / 60;
        //秒
        long seconds = totalSeconds % 60;

        if (hours > 0) {
            return String.format(Locale.getDefault(), "%02d:%02d:%02d", hours, minutes, seconds);
        } else {
            return String.format(Locale.getDefault(), "%02d:%02d", minutes, seconds);
        }
    }
}
